# Gilardi, Fabrizio, "The Temporary Importance of Role Models for Women's Political Representation", American Journal of Political Science
# Code to replicate Table SI27 (Replication of Table A7: OLS regression coefficients and standard errors)
# gilardi@ipz.uzh.ch, 2014-06-24

# Set working directory
setwd("../Data/")

# Load packages
library(texreg)

# Load data
d <- read.csv("dataset-full.csv")

# Compute new variables
d$at.least.one.woman.cand.previously.elected <- d$n.women.cand.previously.elected
d$at.least.one.woman.cand.previously.elected[d$n.women.cand.previously.elected > 0] <- 1


###################
# Estimate models #########################################
###################

out.5w <- lm(ratio.votes.w.min.e ~ sl.autob.n.women.elected + n.women.elected.lagged + n.women.cand.previously.elected + n.men.cand.previously.elected + n.women.cand + n.people.elected + referenda + wom.kr + log.dist.zh + log.pop + kr.svp + steuerfuss + as.factor(stadt.land) + sl.autob.n.women.elected*as.factor(year), data=d)
summary(out.5w)

out.6w <- lm(ratio.votes.w.min.e ~ sl.autob.n.women.elected + at.least.one.woman.elected.lagged + at.least.one.woman.cand.previously.elected + n.men.cand.previously.elected + n.women.cand + n.people.elected + referenda + wom.kr + log.dist.zh + log.pop + kr.svp + steuerfuss + as.factor(stadt.land) + sl.autob.n.women.elected*as.factor(year), data=d)
summary(out.6w)

out.7w <- lm(ratio.votes.mean.w.m ~ sl.autob.n.women.elected + n.women.elected.lagged + n.women.cand.previously.elected + n.men.cand.previously.elected + n.women.cand + n.people.elected + referenda + wom.kr + log.dist.zh + log.pop + kr.svp + steuerfuss + as.factor(stadt.land) + sl.autob.n.women.elected*as.factor(year), data=d)
summary(out.7w)

out.8w <- lm(ratio.votes.mean.w.m ~ sl.autob.n.women.elected + at.least.one.woman.elected.lagged + at.least.one.woman.cand.previously.elected + n.men.cand.previously.elected + n.women.cand + n.people.elected + referenda + wom.kr + log.dist.zh + log.pop + kr.svp + steuerfuss + as.factor(stadt.land) + sl.autob.n.women.elected*as.factor(year), data=d)
summary(out.8w)



##############
# Make table ########################################
##############

var.names <- c(
	"(Intercept)",
	"Spatial lag",
	"Nr. xfemale elected ($t-1$)",
	"Nr. xfemale incumbent cand. ($t-1$)",
	"Nr. xmale incumbent cand. ($t-1$)",
	"Nr. xfemale cand.",
	"Nr. seats",
	"Referenda on gender equality",
	"Support for xfemale in cantonal elec.",
	"Distance from Zurich (log)",
	"Population (log)",
	"Support for conservative party",
	"Tax level",
	"Suburb",
	"Countryside",
	seq(1978, 2010, 4),
	"Spatial lag $xx$ 1978",
	"Spatial lag $xx$ 1982",
	"Spatial lag $xx$ 1986",
	"Spatial lag $xx$ 1990",
	"Spatial lag $xx$ 1994",
	"Spatial lag $xx$ 1998",
	"Spatial lag $xx$ 2002",
	"Spatial lag $xx$ 2006",
	"Spatial lag $xx$ 2010",
	"Nr. xfemale elected ($t-1$) $>0$",
	"Nr. xfemale incumbent cand. ($t-1$) $>0$"
)

model.names <- c("(5)", "(6)", "(7)", "(8)")

texreg(list(out.5w, out.6w, out.7w, out.8w), single.row=T, center=T, dcolumn=T, custom.model.names=model.names, custom.coef.names=var.names)






